// 依赖&组件
import Vue from 'vue'
import App from './App'
import IM from "@/im/im.js" // IM
import dayjs from "dayjs";
Vue.prototype.$im = IM;
uni.$im = IM;
Vue.prototype.$dayjs = dayjs;
uni.$dayjs = dayjs;
// #ifndef VUE3
import store from '@/store' // store
Vue.prototype.$store = store;
import plugins from './plugins' // plugins
import quickButton from "@/components/quick-button/quick-button.vue"

import * as util from 'utils/util.js'
import uView from "uview-ui"
import "@/utils/filter.js"
import * as encrypt from "@/utils/encrypt.js"; // 加解密函数
import * as utils from "@/utils";
import { getAge } from "@/utils/age.js";
// import "@/utils/dayjs.js"; // 引入dayjs方法
// require('utils/dateUtils.js')
import { toAwait } from "@/utils/to-await.js"; // 引入toAwait方法，处理await接收值
// import Lack from "@/components/lack/lack.vue";
// import TabBar from "@/components/tabbar/tab-bar.vue";
// import MyButton from "@/components/my-button/my-button.vue";
// import MyLayouts from "@/components/my-layouts/my-layouts.vue";
// import MyDialog from "@/components/my-dialog/my-dialog.vue";




Vue.prototype.$toAwait = toAwait;
Vue.prototype.$utils = Object.assign({}, utils, encrypt);
Vue.prototype.$getAge = getAge;
Vue.prototype.$toast = function (title = "提示", icon = "none") {
	uni.showToast({
		title,
		icon,
	});
};


uni.$utils = Object.assign({}, utils, encrypt);
uni.$toAwait = toAwait;
uni.$getAge = getAge;
// 组件
Vue.use(plugins)
Vue.use(uView)
Vue.component('quick-button', quickButton)
// Vue.component("lack", Lack);
// Vue.component("TabBar", TabBar);
// Vue.component('my-button', MyButton);
// Vue.component('my-layouts', MyLayouts);
// Vue.component('my-dialog', MyDialog);
// 方法
//校验手机号
Vue.prototype.phoneFun = function (phones) {
	var myreg = /^[1][3,4,5,7,8,9][0-9]{9}$/;
	if (!myreg.test(phones)) {
		console.log("手机号格式不正确");
		return false;
	} else {
		console.log("手机号格式正确");
		return true;
	}
};
/**
 * 传入身份证号码，获取出生日期、性别和年龄
 * @param IdCard 身份证号码
 * @param type 1 获取出生日期
 *             2 获取性别
 *             3 获取年龄，年龄小于1岁时默认为1岁
 */
Vue.prototype.IdCard = function (IdCard, type) {
	if (type === 1) {
		//获取出生日期
		var birthday =
			IdCard.substring(6, 10) +
			"-" +
			IdCard.substring(10, 12) +
			"-" +
			IdCard.substring(12, 14);
		return birthday;
	}
	if (type === 2) {
		//获取性别
		if (parseInt(IdCard.substr(16, 1)) % 2 == 1) {
			return "男";
		} else {
			return "女";
		}
	}
	if (type === 3) {
		//获取年龄
		var ageDate = new Date();
		var month = ageDate.getMonth() + 1;
		var day = ageDate.getDate();
		var age = ageDate.getFullYear() - IdCard.substring(6, 10) - 1;
		if (
			IdCard.substring(10, 12) < month ||
			(IdCard.substring(10, 12) == month && IdCard.substring(12, 14) <= day)
		) {
			age++;
		}
		if (age <= 0) {
			age = 1;
		}
		return age;
	}
};





Vue.config.productionTip = false
App.mpType = 'app'
//html转普通文本，去除样式
Vue.filter("htmlToTextFilters", (text) => {
	if (!text) {
		return ''
	}
	return util.removeHtmlStyle(text)
})
const app = new Vue({
	...App
})

app.$mount()
// #endif

// #ifdef VUE3
import { createSSRApp } from "vue";
export function createApp() {
	const app = createSSRApp(App);
	return {
		app,
	};
}
// #endif